unit recent;

interface
uses classes,menus, sysutils,

main, media; 

type TKRecent = class
   rclist: tstringlist;
   frm: TKliperMainform;
   constructor Create;
   procedure addRecent(media: TKMedia);
   procedure removeRecent(media: TKMedia);
   procedure loadFromFile(url: string);
   procedure saveToFile(url: string);
end;


implementation
{ TKRecent }

procedure TKRecent.addRecent(media: TKMedia);
var
  ind: integer;
  x: tmenuitem;
  found: boolean;
begin
 for ind := 0 to rclist.Count - 1 do if rclist.Strings[ind] = media.url then
      found := true;
  if found then
  begin
    //already on list, so just left it out.
  end else begin
    if rclist.Count >= 10 then begin
      rclist.Delete(0);
      frm.lastOpenmenu.Delete(0);
    end;
    x := tmenuitem.Create(mainform);
    x.Caption := media.url;
    x.Tag := rclist.Count;
//FixME    x.OnClick := 
    rclist.Add(media.url);
    mainform.lastOpenmenu.Add(x);
  end;

end;

constructor TKRecent.Create;
begin
  rclist:=tstringlist.create;
end;

procedure TKRecent.loadFromFile(url: string);
var myitem: tmenuitem;
var i: integer;
begin
   rclist.LoadFromFile(extractfiledir(paramstr(0)) + '\recent.ini');
    for i := 0 to rclist.Count - 1 do begin
      myitem := tmenuitem.Create(frm);
      myitem.Caption := extractfilename(rclist[i]);
      myitem.Tag := i;
//      myitem.OnClick := frm.onrecentclick;
      frm.lastopenmenu.Add(myitem);
    end;
end;

procedure TKRecent.removeRecent(media: TKMedia);
begin

end;

procedure TKRecent.saveToFile(url: string);
begin
  rclist.saveToFile(Extractfiledir(paramstr(0))+ '\recent.ini');
end;


end.
